package com.ruoyi.generator.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.GenTableColumn;
import com.ruoyi.common.core.domain.ColumnParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 阀体-执行器 数据层
 *
 * @author he
 * @date 2021-04-16
 */
public interface TbMapper {
    /**
     * @param tbName
     * @param queryColumns
     * @param isLogic      是否逻辑查询, deleted 是否生效
     * @return
     */
    List<Map<String, Object>> getList(@Param("tbName") String tbName, @Param("selectColumns") List<String> selectColumns, @Param("queryColumns") List<GenTableColumn> queryColumns, @Param("isLogic") boolean isLogic, @Param("page") Page page);

    List<Map<String, Object>> getListByColumnQuery(@Param("tbName") String tbName, @Param("selectColumns") List<String> selectColumns, @Param("queryColumns") List<ColumnParam> queryColumns, @Param("isLogic") boolean isLogic, @Param("page") Page page);

    List<Map<String, Object>> getByIdsLogic(@Param("tbName") String tbName, @Param("selectColumns") List<String> selectColumns, @Param("idColName") String idColName, @Param("idColValues") Object[] idColValue);

    Map<String, Object> getOneByField(@Param("tbName") String tbName, @Param("selectColumns") List<String> selectColumns, @Param("idColName") String idColName, @Param("idColValue") Object idColValue, @Param("isLogic") boolean isLogic);

    int insert(@Param("tbName") String tbName, @Param("colNames") List<String> colNames, @Param("colValues") List<Object> colValues);

    int updateById(@Param("tbName") String tbName, @Param("idColName") String idColName, @Param("idColValue") Object idColValue, @Param("cols") List<GenTableColumn> cols);

    int update(@Param("tbName") String tbName, @Param("queryColumns") List<ColumnParam> queryColumns, @Param("cols") List<GenTableColumn> cols);

    int deleteByIds(@Param("tbName") String tbName, @Param("idColName") String idColName, @Param("idColValues") Object[] idColValue);
    int backupByIds(@Param("tbName") String tbName, @Param("idColName") String idColName, @Param("idColValues") Object[] idColValue, @Param("businessType") Integer businessType);

    int deleteByIdsLogic(@Param("tbName") String tbName, @Param("idColName") String idColName, @Param("idColValues") Object[] idColValue);

    @Update("update ${tbName} set ${col} = ${col} + ${havVal} where ${idColName} = #{idVal}")
    int addHav(@Param("tbName") String shortTbName, @Param("col") String col,@Param("havVal") int havVal, @Param("idColName") String idColName, @Param("idVal") Object idVal);

    int updateByCopyIds(@Param("tbName") String tbName, @Param("updateColName") String updateColName, @Param("whereColName") String whereColName, @Param("whereValue") String whereValue,  @Param("ids") Object[] ids);

}